
var $ = require('../lib/jquery-1.12.1.min.js');

"use strict";
var mgr = {
    
    init: function () {
        var me = this;

            console.log(+new Date);
            me.initTable();

            console.log(+new Date);
    },
    
    initTable: function () {
        var me = this;

        me.grid =  $('#grid-container').jtable({
           
            rowNumber: true,
            pagination: true,
            hasCheckbox: true,
            checkboxValueField: 'id',
            gridHeader: {
                title: '权限管理列表',
                icon: 'iconfont icon-mokuaiguanlierji',
                toolbar: [{
                    icon: 'iconfont icon-refresh1',
                    handle: function (e) {
                        var grid = e.data;
                        grid.reload();
                        console.log('toolbar icon click');
                    }
                }]
            },
            toolbar: [{
                text: '添加',
                icon: 'iconfont icon-add',
                handle: function ( e ) {
                    e.data = me;
                    me.addDialogHandle.call(this, e);
                }
            },{
                text: '修改',
                icon: 'iconfont icon-edit',
                handle: function ( e ) {
                    e.data = me;
                    me.editDialogHandle.call(this, e);
                }
            },{
                text: '删除',
                icon: 'iconfont icon-edit',
                handle: function ( e ) {
                    e.data = me;
                    me.delActionHandle.call(this, e);
                }
            },{
                text: '进入子模块',
                icon: 'iconfont icon-mokuaiguanlierji',
                handle: function ( e ) {
                    e.data = me;
                    me.jumpInModuleHandle.call(this, e);
                }
            }],
            source: {
                data: [{
                    id: 1,
                    moduleName: '模块名称',
                    owner: 'My Modules',
                    desc: '描述内容',
                    status: 1,
                    gmtCreate: +new Date
                },{
                    id: 2,
                    moduleName: '模块名称',
                    owner: 'My Modules',
                    desc: '描述内容',
                    status: 1,
                    gmtCreate: +new Date
                },{
                    id: 3,
                    moduleName: '模块名称',
                    owner: 'My Modules',
                    desc: '描述内容',
                    status: 1,
                    gmtCreate: +new Date
                }],
                totalCount: 1
            },
            columns: [{
                title: 'ID',
                field: 'id',
                width: '60'
            },{
                title: '模块名称',
                field: 'moduleName',
                width: '20%'
            },{
                title: '拥有者',
                field: 'owner',
                width: '100'
            },{
                title: '描述',
                field: 'desc',
                width: 150
            },{
                title: '状态',
                field: 'status',
                width: '60',
                formatter: function (val, row) {
                    if ( val === -1 ) {
                        return '<span style="color:red" >删除</span>';
                    } else if ( val === 1 ) {
                        return '<span style="color:green" >正常</span>';
                    }
                }
            },{
                title: '创建时间',
                field: 'gmtCreate',
                width: 140,
                formatter: function (val, row) {
                    //return Util.Date.format(val,'yyyy-mm-dd hh:mm:ss');
                }
            }]
        });
    }
};

mgr.init();
